package ${basePackage}.service.impl;

import com.github.pagehelper.PageHelper;
import ${basePackage}.mapper.${modelNameUpperCamel}Mapper;
import ${basePackage}.model.*;
import ${basePackage}.service.${modelNameUpperCamel}Service;
import ${basePackage}.util.ServiceUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ${author} on ${date}.
 */
@Service
public class ${modelNameUpperCamel}ServiceImpl implements ${modelNameUpperCamel}Service {
    @Autowired
    private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;

    @Override
    public int create(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return ${modelNameLowerCamel}Mapper.insert(${modelNameLowerCamel});
    }

    @Override
    public int update(Long id, ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}.setId(id);
        return ${modelNameLowerCamel}Mapper.updateByPrimaryKeySelective(${modelNameLowerCamel});
    }

    @Override
    public ${modelNameUpperCamel} getItem(Long id) {
        return ${modelNameLowerCamel}Mapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        return ${modelNameLowerCamel}Mapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<${modelNameUpperCamel}> list(${modelNameUpperCamel} ${modelNameLowerCamel}, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        ${modelNameUpperCamel}Example example = new ${modelNameUpperCamel}Example();
        ${modelNameUpperCamel}Example.Criteria criteria = example.createCriteria();
        ServiceUtil.andAllEqualTo(${modelNameUpperCamel}Example.Criteria.class, criteria, ${modelNameUpperCamel}.class, ${modelNameLowerCamel});
        return ${modelNameLowerCamel}Mapper.selectByExample(example);
    }
}
